package com.gome.bg.util;

import java.util.Calendar;
import java.util.HashMap;
import com.gome.bg.util.rbToATG.*;
import com.gome.util.TraceInfo;

import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl;
@SuppressWarnings("unchecked")
public class DwrContextUtil {

	private static DwrContextUtil instance;
	
	private HashMap mymap;
	
	private DwrContextUtil() {
		mymap = new HashMap();
		this.AddDwrContext();
	}
	public static DwrContextUtil getInstance() {
		if (instance == null) {
			instance = new DwrContextUtil();
		}
		return instance;
	}
	

	public synchronized void AddDwrContext() {
		String sit = "http://10.126.53.117:7013/scheduler/ws/rb_refund/RefundAuditServerInterface?wsdl";
		String uat = "http://10.126.45.25:7018/scheduler/ws/rb_refund/RefundAuditServerInterface?wsdl";
		String pre = "http://10.58.44.52:7013/scheduler/ws/rb_refund/RefundAuditServerInterface?wsdl";
		//String pro = "http://job.ds.gome.com.cn/scheduler/ws/rb_refund/RefundAuditServerInterface?wsdl";
		mymap.put("sit", sit);
		mymap.put("uat", uat);
		mymap.put("pre", pre);
		//mymap.put("pro", pro);
	}
	public synchronized String getUrl(String se_id) {
		if (se_id == null)
			return null;
		return (String) mymap.get(se_id);
	}
	
	/**
	 * Calendar转为XMLGregorianCalendar
	 * @param calendar
	 * @return
	 */
	   public static XMLGregorianCalendar convert(Calendar calendar){   
	       XMLGregorianCalendar cal = new XMLGregorianCalendarImpl();   
	       cal.setYear(calendar.get(Calendar.YEAR));   
	       cal.setMonth(calendar.get(Calendar.MONTH) +1);   
	       cal.setDay(calendar.get(Calendar.DAY_OF_MONTH));   
	       cal.setHour(calendar.get(Calendar.HOUR_OF_DAY));   
	       cal.setMinute(calendar.get(Calendar.MINUTE));   
	       cal.setSecond(calendar.get(Calendar.SECOND));   
	       cal.setMillisecond(calendar.get(Calendar.MILLISECOND));   
	       cal.setTimezone(calendar.get(Calendar.ZONE_OFFSET) / 60000 );   
	       return cal;   
	   }

	
	
	public static RefundAuditResultReply isCallAtGSuccess(RefundAuditResult res,String serviceUrl){
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		RefundAuditResultReply resReply = new RefundAuditResultReply();
		factory.setServiceClass(RefundAuditServerInterface.class);
		factory.setAddress(serviceUrl);
		RefundAuditServerInterface client = (RefundAuditServerInterface) factory.create();
		TraceInfo.traceInfo(client);
		resReply = client.isCallSuccess(res);
		TraceInfo.traceInfo(resReply);
		System.out.println("resReply=="+resReply);
		return resReply;
	}

	
}
